package com.chj.collector;

import com.chj.data.TempData;
import io.prometheus.client.Collector;
import io.prometheus.client.CounterMetricFamily;
import io.prometheus.client.GaugeMetricFamily;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class CustomizeCollector extends Collector {

    public CustomizeCollector() {
        super();
    }

    @Override
    public List<MetricFamilySamples> collect() {
        List<MetricFamilySamples> mfs = new ArrayList();
        this.addMetrics1(mfs);
        this.addMetrics2(mfs);
        return mfs;
    }

    void addMetrics1(List<MetricFamilySamples> sampleFamilies) {
        String metricName = "my_guage_1";

        // Your code to get metrics
        MetricFamilySamples.Sample sample = new MetricFamilySamples.Sample(metricName, Arrays.asList("l1"), Arrays.asList("v1"), getRandomValue());
        MetricFamilySamples.Sample sample2 = new MetricFamilySamples.Sample(metricName, Arrays.asList("l1", "l2"), Arrays.asList("v1", "v2"), getRandomValue());
        MetricFamilySamples samples = new MetricFamilySamples(metricName, Type.COUNTER, "help", Arrays.asList(sample, sample2));
        sampleFamilies.add(samples);
    }

    void addMetrics2(List<MetricFamilySamples> sampleFamilies) {
        Random random = new Random(100);
        sampleFamilies.add(new GaugeMetricFamily("my_guage_2", "************my_guage_2************", getRandomValue()));
        sampleFamilies.add(new CounterMetricFamily("my_guage_3", "************my_guage_3************", getRandomValue()));
        sampleFamilies.add(new CounterMetricFamily("my_guage_4", "************my_guage_4************", getRandomValue()));
        sampleFamilies.add(new CounterMetricFamily("my_guage_5", "************my_guage_4************", TempData.temp));
    }

    double getRandomValue(){
        Random random = new Random();
        return random.nextDouble();
    }





}
